use regex::Regex;

fn main() {
    let markdown_text =
        "# Header 1\n## Header 2\n### Header 3\n#### Header 4\n##### Header 5\n###### Header 6";
    let reg = Regex::new(r"(?m)^(#{1,6})\s+(.+)$").unwrap();
    for cap in reg.captures_iter(markdown_text) {
        let level = cap[1].len();
        let header = cap[2].trim();
        println!("标题等级：{}；文本: \"{}\"", level, header)
    }
}

#[test]
fn regex_markdown_test() {
    let markdown_text =
        "# Header 1\n## Header 2\n### Header 3\n#### Header 4\n##### Header 5\n###### Header 6";
    let reg = Regex::new(r"(?m)^(#{1,6})\s+(.+)$").unwrap();
    for cap in reg.captures_iter(markdown_text) {
        let level = cap[1].len();
        let header = cap[2].trim();
        println!("标题等级：{}；文本: \"{}\"", level, header)
    }
}
